package com.letv.app.ljodfh.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.canyinghao.canrefresh.CanRefreshLayout;
import com.google.gson.Gson;
import com.jiongbull.jlog.JLog;
import com.letv.app.ljodfh.base.Cache;
import com.letv.app.ljodfh.base.Constances;
import com.letv.app.ljodfh.beans.NewsClickCountBean;
import com.letv.app.ljodfh.beans.NewsIdBean;
import com.letv.app.ljodfh.beans.NewsListClickRequestBean;
import com.letv.app.ljodfh.beans.NewsListClickVo;
import com.letv.app.ljodfh.ui.adapter.HomePagerAdapter;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.ruihang.generalibrary.utils.DateUtils;
import com.ruihang.generalibrary.utils.GroupOrderHelperSingled;
import com.ruihang.generalibrary.utils.ListUtils;
import com.letv.app.ljodfh.R;
import com.letv.app.ljodfh.base.BaseActivity;
import com.letv.app.ljodfh.beans.FocusColumn;
import com.letv.app.ljodfh.beans.HomeListItem;
import com.letv.app.ljodfh.beans.HomeLive;
import com.letv.app.ljodfh.beans.HomePopular;
import com.letv.app.ljodfh.beans.LiveItem;
import com.letv.app.ljodfh.beans.NewsDate;
import com.letv.app.ljodfh.beans.NewsItem;
import com.letv.app.ljodfh.beans.Titles;
import com.letv.app.ljodfh.http.AbsListNetCallback;
import com.letv.app.ljodfh.http.AbsNetCallBack;
import com.letv.app.ljodfh.http.NetUtils;
import com.letv.app.ljodfh.ui.activities.MainActivity;
import com.letv.app.ljodfh.ui.adapter.GreatestAdapter;
import com.letv.app.ljodfh.ui.util.IListShowData;
import com.letv.app.ljodfh.ui.util.NewsDateComparator;
import com.letv.app.ljodfh.ui.utils.GreatestDataAddHelper;
import com.letv.app.ljodfh.ui.utils.MutilDateNewsGetHelper;
import com.letv.app.ljodfh.ui.utils.SkipUtil;
import com.letv.app.ljodfh.utils.ListTypeUtils;

import org.xutils.common.util.DensityUtil;

import java.sql.Date;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/6/29 0029.
 */
public class GreatestFragment extends ColumnBaseFragment implements CanRefreshLayout.OnRefreshListener
        , CanRefreshLayout.OnLoadMoreListener {

    private static final int WHAT_GET_EXPRESS = 551;
    private static final long SPACE_GET_EXPRESS = 60000L;

    @BindView(R.id.common_refresh)
    protected CanRefreshLayout refreshLayout;
    @BindView(R.id.can_content_view)
    protected RecyclerView recyclerView;
    private LinearLayoutManager layoutManager;
    private GreatestAdapter adapter;

    private GreatestDataAddHelper dataAddHelper;

    private GroupOrderHelperSingled groupOrderHelper;

    private String hour24UrlTemp, bannerUrlTemp, liveUrlTemp, /**
     * expressUrlTemp,
     **/
    popularUrlTemp;
    private int current24Page = -1, secTitlePos = -1;
    private Date first24TitleDateTemp;

    private MutilDateNewsGetHelper hour24GetHelper;
    private int newsFlashType = 0;

    private boolean isReset;

    private Handler handler;

    //    private LittleLifeManager littleLifeManager;

    private long lastGetTime = -1;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                if (msg != null) {
                    parseMsg(msg);
                }
            }
        };
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_greatest, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
//        JLog.e("okh  parent=" + isParentShowing + "  this=" + isThisShowing + "  count=" + getShowCount() + "  front=" + isFront);
    }

    @Override
    protected void onFragmentUnShowed(boolean isCallFromPause) {
        if (adapter != null) {
            adapter.onPause();
        }
        handler.removeMessages(WHAT_GET_EXPRESS);
        super.onFragmentUnShowed(isCallFromPause);
    }

//    @Override
//    public void onPause() {
//        if (adapter != null) {
//            adapter.onPause();
//        }
//        super.onPause();
//    }

    @Override
    public void onDestroy() {
        if (adapter != null) {
            adapter.onDestory();
            adapter = null;
        }
        super.onDestroy();
    }

    @Override
    public void onLoadMore() {
        if (groupOrderHelper.getCount() <= 0) {
            getNews24Page(false);
        } else {
            if (refreshLayout.isRefreshing()) {
                refreshLayout.loadMoreComplete();
            }
        }
    }

    @Override
    public void onRefresh() {
        isRefresh = true;
        getChannelList();
    }

    @Override
    protected void initViews(View v, @Nullable Bundle savedInstanceState) {
        layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
//        sss();
//        adapter = dataAddHelper.getAdapter(getContext());
//        adapter.setBannerActiveClick(activeClick);
//        recyclerView.setAdapter(adapter);
        refreshLayout.setOnRefreshListener(this);
        refreshLayout.setOnLoadMoreListener(this);
        refreshLayout.setLoadMoreEnabled(false);
        groupOrderHelper = new GroupOrderHelperSingled();
    }

    @Override
    protected boolean onFragmentShow(boolean isFirst, boolean isCallFromResume) {
        if (isFirst) {
            refreshLayout.autoRefresh();
        }
        if (adapter != null) {
            adapter.onResume();
        }
        JLog.e("okh  last time=" + lastGetTime);
        if (lastGetTime > 0) {
            long ca = SystemClock.elapsedRealtime() - lastGetTime;
            JLog.e("okh  will send msg  ca=" + ca);
            if (ca >= SPACE_GET_EXPRESS) {
                handler.sendEmptyMessage(WHAT_GET_EXPRESS);
            } else {
                handler.sendEmptyMessageDelayed(WHAT_GET_EXPRESS, SPACE_GET_EXPRESS - ca);
            }
        }
        return super.onFragmentShow(isFirst, isCallFromResume);
    }

    private Message createExpressGetMsg() {
        Message msg = Message.obtain();
        msg.what = WHAT_GET_EXPRESS;
        return msg;
    }

    private void parseMsg(Message msg) {
        if (msg.what == WHAT_GET_EXPRESS) {
            handler.removeMessages(WHAT_GET_EXPRESS);
            lastGetTime = SystemClock.elapsedRealtime();
//            if (getExpressChannel(expressUrlTemp) <= 0 && dataAddHelper != null) {
//                dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_EXPRESS);
//            }
            handler.sendEmptyMessageDelayed(WHAT_GET_EXPRESS, SPACE_GET_EXPRESS);
        }
    }

    private void getChannelList() {
        if (TextUtils.isEmpty(channelUrl)) {
            toast("数据错误");
            JLog.e("int " + this.getClass().getSimpleName() + " url wrong ::" + channelUrl);
            refreshLayout.refreshComplete();
            return;
        }
        NetUtils.getNetAdapter().getChannelArray(getOwnerName(), channelUrl, new AbsListNetCallback<FocusColumn>(ListTypeUtils.FocusColums()) {
            @Override
            public void onSuc(List<FocusColumn> focusColumns) {
                if (ListUtils.isListValued(focusColumns)) {
                    resetUrlTemps();
                    for (FocusColumn fc :
                            focusColumns) {
                        if (fc != null) {
                            switch (fc.getSubChannelType()) {
                                case GreatestAdapter.VIEWTYPE_BANNER:
                                    bannerUrlTemp = fc.getChannelUrl();
                                    break;
//                                case GreatestAdapter.VIEWTYPE_EXPRESS:
//                                    expressUrlTemp = fc.getChannelUrl();
//                                    break;
                                case GreatestAdapter.VIEWTYPE_LIVE:
                                    liveUrlTemp = fc.getChannelUrl();
                                    break;
                                case GreatestAdapter.VIEWTYPE_NEWS_24:
                                    hour24UrlTemp = fc.getChannelUrl();
                                    break;
                                case GreatestAdapter.VIEWTYPE_POPULAR:
                                    popularUrlTemp = fc.getChannelUrl();
                                    break;
                            }
                        }
                    }
                    if (dataAddHelper == null) {
                        dataAddHelper = new GreatestDataAddHelper();
                    }
                    if (getNewsArray(bannerUrlTemp, GreatestAdapter.VIEWTYPE_BANNER) <= 0) {
                        dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_BANNER);
                    }
//                            if (!getNewsArray(expressUrlTemp, GreatestAdapter.VIEWTYPE_EXPRESS)) {
//                    if (getExpressChannel(expressUrlTemp) <= 0) {
//                        dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_EXPRESS);
//                    }
                    lastGetTime = SystemClock.elapsedRealtime();
                    handler.removeMessages(WHAT_GET_EXPRESS);
                    handler.sendEmptyMessageDelayed(WHAT_GET_EXPRESS, SPACE_GET_EXPRESS);
                    if (!getLiveArray(liveUrlTemp)) {
                        dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_LIVE);
                    }
//                            if (!getNewsArray(popularUrlTemp, GreatestAdapter.VIEWTYPE_POPULAR)) {
                    if (!getHomePopular(popularUrlTemp)) {
                        dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_POPULAR);
                    }
                    if (!getNews24Date()) {
                        dataAddHelper.remove24data();
                    }
                }
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
                refreshLayout.refreshComplete();
            }
        });
    }

    private int getExpressChannel(String url) {
        if (TextUtils.isEmpty(url)) {
            return 0;
        }
        if (!groupOrderHelper.addOne(30)) {
            return 1;
        }
        NetUtils.getNetAdapter().getChannelArray(getOwnerName(), url, new AbsNetCallBack<List<FocusColumn>>(ListTypeUtils.FocusColums()) {
            @Override
            public void onSuc(List<FocusColumn> focusColumns) {
                if (ListUtils.isListValued(focusColumns)) {
                    FocusColumn fc = focusColumns.get(0);
                    if (fc == null) {
                        return;
                    }
                    newsFlashType = fc.getNewsFlashType();
                    if (getNewsArray(fc.getChannelUrl(), GreatestAdapter.VIEWTYPE_EXPRESS) <= 0) {
                        dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_EXPRESS);
                    }
                }
            }

            @Override
            public void onEnd() {
                super.onEnd();
                onNetFinish(30);
            }
        });
        return 2;
    }

    private boolean getHomePopular(String url) {
        if (TextUtils.isEmpty(url)) {
            return false;
        }
        if (!groupOrderHelper.addOne(GreatestAdapter.VIEWTYPE_POPULAR)) {
            return false;
        }
        NetUtils.getNetAdapter().getHomePopular(getOwnerName(), url, new AbsNetCallBack<HomePopular>(HomePopular.class) {
            @Override
            public void onSuc(HomePopular homePopular) {
                if (homePopular != null && ListUtils.isListValued(homePopular.getNewsList())) {
                    HomeListItem hb = new HomeListItem();
                    hb.setNewsItemList(homePopular.getNewsList());
                    hb.setViewType(GreatestAdapter.VIEWTYPE_POPULAR);
                    hb.setSubUrl(homePopular.getMoreList());
//                    if (ListUtils.isListValued(homePopular.getMoreList())) {
//                        NewsItem ni = homePopular.getMoreList().get(0);
//                        hb.setSubUrl(ni.getNewsUrl());
//                    }
                    dataAddHelper.setUpDatas(getContext(), hb, GreatestAdapter.VIEWTYPE_POPULAR);//暂时使用calledIndex来保存mode
                } else {
                    dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_POPULAR);//暂时使用calledIndex来保存mode
                }
            }

            @Override
            public void onEnd() {
                super.onEnd();
                onNetFinish(GreatestAdapter.VIEWTYPE_POPULAR);//暂时使用calledIndex来保存mode
            }
        });
        return true;
    }

    private int getNewsArray(String url, final int mode) {
        if (TextUtils.isEmpty(url)) {
            JLog.e("int " + this.getClass().getSimpleName() + " url wrong ::" + url + "  mode=" + mode);
            return 0;
        }
        if (!groupOrderHelper.addOne(mode)) {
            return 1;
        }
        NetUtils.getNetAdapter().getNewsArray(getOwnerName(), url, new AbsListNetCallback<NewsItem>(ListTypeUtils.NewsItem(), mode) {//暂时使用calledIndex来保存mode
            @Override
            public void onSuc(List<NewsItem> newsItems) {
                if (ListUtils.isListValued(newsItems)) {
                    HomeListItem hb = new HomeListItem();
                    hb.setNewsItemList(newsItems);
                    hb.setViewType(calledIndex);
                    hb.setSubType(newsFlashType);
                    dataAddHelper.setUpDatas(getContext(), hb, calledIndex);//暂时使用calledIndex来保存mode
                } else {
                    dataAddHelper.removeUpItem(calledIndex);//暂时使用calledIndex来保存mode
                }
            }

            @Override
            public void onEnd() {
                super.onEnd();
                onNetFinish(calledIndex);//暂时使用calledIndex来保存mode
            }
        });
        return 2;
    }

    private boolean getLiveArray(String url) {
        if (TextUtils.isEmpty(url)) {
            JLog.e("int " + this.getClass().getSimpleName() + " live url wrong ::" + url);
            return false;
        }
        if (!groupOrderHelper.addOne(GreatestAdapter.VIEWTYPE_LIVE)) {
            return false;
        }
        NetUtils.getNetAdapter().getLiveArray(getOwnerName(), url, new AbsListNetCallback<LiveItem>(ListTypeUtils.LiveItem()) {
            @Override
            public void onSuc(List<LiveItem> liveItems) {
                if (ListUtils.isListValued(liveItems)) {
                    HomeLive hli = new HomeLive();
                    hli.setLiveList(liveItems);
                    hli.setViewType(GreatestAdapter.VIEWTYPE_LIVE);
                    dataAddHelper.setLiveData(getContext(), hli);
                } else {
                    dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_LIVE);
                }
            }

            @Override
            public void onEnd() {
                super.onEnd();
                onNetFinish(GreatestAdapter.VIEWTYPE_LIVE);
            }
        });
        return true;
    }

    private boolean getNews24Date() {
        if (TextUtils.isEmpty(hour24UrlTemp)) {
            JLog.e("int " + this.getClass().getSimpleName() + " 24h url wrong ::" + hour24UrlTemp + "  page=" + current24Page);
            return false;
        }
        if (!groupOrderHelper.addOne(GreatestAdapter.VIEWTYPE_NEWS_24)) {
            return false;
        }
        NetUtils.getNetAdapter().getNewsDateArray(getOwnerName(), hour24UrlTemp, new AbsListNetCallback<NewsDate>(ListTypeUtils.NewsItem()) {
            private int te = 0;

            @Override
            public void onSuc(List<NewsDate> newsItems) {
                if (ListUtils.isListValued(newsItems)) {
                    init24Helper().setDates(newsItems);

                    getNews24Page(true);
                }
            }

            @Override
            public List<NewsDate> doInBackground(List<NewsDate> newsDates) {
                if (ListUtils.isListValued(newsDates)) {
                    Collections.sort(newsDates, new NewsDateComparator());
                }
                return super.doInBackground(newsDates);
            }

            @Override
            public void onEnd() {
                super.onEnd();
                onNetFinish(GreatestAdapter.VIEWTYPE_NEWS_24);
            }
        });
        return true;
    }

    private MutilDateNewsGetHelper init24Helper() {
        if (hour24GetHelper == null) {
            hour24GetHelper = new MutilDateNewsGetHelper(this);
            hour24GetHelper.setShouldSetTitleAfter(true);
        }
        return hour24GetHelper;
    }

    private boolean getNews24Page(final boolean reset) {
        if (!init24Helper().hasValuedDate()) {
            dataAddHelper.remove24data();
            return false;
        }
        if (!groupOrderHelper.addOne(241)) {
            return false;
        }
        isReset = reset;
        hour24GetHelper.getNewsList(20, reset
                , new AbsListNetCallback<IListShowData>(IListShowData.class) {

                    @Override
                    public void onSuc(List<IListShowData> newsItems) {
                        if (ListUtils.isListValued(newsItems)) {
//                            dataAddHelper.addOrSet24Datass(getContext(), newsItems, reset);
                            requestNewsClickCount( newsItems, reset);
                        } else {
                            if (calledIndex <= 0) {
                                dataAddHelper.remove24data();
                                current24Page = calledIndex;
                            }
                        }
                    }

                    @Override
                    public void onEnd() {
                        super.onEnd();
                        isRefresh = false;
                        onNetFinish(241);
                    }
                });
        return true;
    }

    private List<IListShowData> newsItems;
//    private List<IListShowData> newsList = new ArrayList<>();
    private boolean isRefresh = false;

    /**
     * 获取新闻列表点击量
     *
     * @param list
     * @param reset
     */
    private void requestNewsClickCount(List<IListShowData> list, final boolean reset) {
        newsItems = new ArrayList<>();
        newsItems.addAll(list);
        List<NewsIdBean> newsIdList = new ArrayList<>();
        NewsIdBean newsBean;
        for (int i = 0; i < list.size(); i++) {
            String type = "10";//默认不返回点击量
            if (list.get(i) instanceof NewsItem) {
                NewsItem item = (NewsItem) list.get(i);
                newsBean = new NewsIdBean();
                newsBean.setId(item.getUrlNewsId());
                switch (item.getNewsType()) {
                    case Constances.NEWS_TYPE_GRAPHIC:
                    case Constances.NEWS_TYPE_AUDIO:
                    case Constances.NEWS_TYPE_VIDEO:
                        //新闻详情
                        type = "0";
                        break;
                    case Constances.NEWS_TYPE_LIVE:
                        //直播详情
                        type = "1";
                        break;
                }
                newsBean.setType(type);
                newsIdList.add(newsBean);
            } else {
                newsBean = new NewsIdBean();
                newsBean.setId("1");
                newsBean.setType(type);
                newsIdList.add(newsBean);
            }
        }
        if (ListUtils.isListValued(newsIdList)) {
            NewsListClickRequestBean requestBean = new NewsListClickRequestBean();
            requestBean.setNewsIds(newsIdList);
            Gson gson = new Gson();
            String newsId = gson.toJson(requestBean);
            RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), newsId);
            NetUtils.getNetAdapter().getViewsList(getOwnerName(), body, new AbsNetCallBack<NewsListClickVo>(NewsListClickVo.class) {
                @Override
                public void onSuc(NewsListClickVo newsListClickVo) {
                    if (null != newsListClickVo && ListUtils.isListValued(newsListClickVo.getResult())) {
                        List<NewsClickCountBean> countList = newsListClickVo.getResult();
                        for (int i = 0; i < countList.size(); i++) {
                            if (newsItems.get(i) instanceof NewsItem) {
                                NewsItem item = (NewsItem) newsItems.get(i);
                                if (countList.get(i).getId().equalsIgnoreCase(item.getUrlNewsId())) {
                                    ((NewsItem) newsItems.get(i)).setReadCount(countList.get(i).getViews());
                                }
                            }
                        }
                    }

                }

                @Override
                public void onEnd() {
                    super.onEnd();
//                    if (isRefresh) {
//                        newsList.clear();
//                        newsList.addAll(newsItems);
//                    } else {
                        if (isRefresh && null != newsItems && newsItems.size() > 1 && newsItems.get(0) instanceof Titles) {
                            newsItems.remove(0);
                        }
                        dataAddHelper.addOrSet24Datass(getContext(), newsItems, reset);
//                    }
                    isRefresh = false;
                    onNetFinish(241);
                }

                @Override
                public void onError(Throwable ex, String errorMsg) {
                    super.onError(ex, errorMsg);
                }
            });
        }
    }

    private List<? extends IListShowData> parse24Datas(List<NewsItem> list) {
        if (secTitlePos > 0) {
            return list;
        }
        ArrayList<IListShowData> li = new ArrayList<>();
        if (first24TitleDateTemp == null) {
            Date date = DateUtils.getDataDate(list.get(0));
            if (date == null) {
                return list;
            }
            Calendar c = Calendar.getInstance();
            c.setTimeInMillis(date.getTime());
            c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
            date.setTime(c.getTimeInMillis());
            first24TitleDateTemp = date;
            Titles t = new Titles();
            t.setDateString(DateUtils.formatDate(date, "MM月dd日"));
            t.setViewType(GreatestAdapter.VIEWTYPE_TITLE_24);
            li.add(t);
        }
        int i = 0;
        while (list.size() > 0) {
            Date d = DateUtils.getDataDate(list.get(i));
            if (d != null) {
                if (d.before(first24TitleDateTemp)) {
                    secTitlePos = i;
                    Titles t = new Titles();
                    t.setDateString(DateUtils.formatDate(d, "MM月dd日"));
                    t.setViewType(GreatestAdapter.VIEWTYPE_TITLE_24_CONTINUE);
                    break;
                }
            }
            li.add(list.remove(i));
            i++;
        }
        if (list.size() > 0) {
            li.addAll(list);
        }

        return li;
    }

    private synchronized void onNetFinish(int mode) {
        if (groupOrderHelper.removeOne(mode)) {
            refreshLayout.refreshComplete();
            refreshLayout.loadMoreComplete();
            refreshLayout.setLoadMoreEnabled(hour24GetHelper != null && !hour24GetHelper.hasGetAll());
        }
        if (adapter == null && dataAddHelper.hasDatas()) {
            adapter = dataAddHelper.getAdapter(getContext());
            adapter.setBannerActiveClick(activeClick);
            recyclerView.setAdapter(adapter);
        }
        if (isReset) {
            isReset = false;
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    recyclerView.smoothScrollToPosition(0);
////                    recyclerView.scrollTo(0,0);
//                    layoutManager.scrollToPositionWithOffset(0,0);
                }
            }, 700);
        }
    }

    private void resetUrlTemps() {
        bannerUrlTemp = null;
//        expressUrlTemp = null;
        hour24UrlTemp = null;
        liveUrlTemp = null;
        popularUrlTemp = null;
        current24Page = -1;
        first24TitleDateTemp = null;
        secTitlePos = -1;
    }

    /**
     * 快讯重磅跳转
     */
    OnItemInternalClick activeClick = new OnItemInternalClick() {
        @Override
        public void onItemInternalClick(View itemView, View view, int position) {
            HomeListItem homeListItem = null;
            if (view == null) {
                homeListItem = (HomeListItem) itemView.getTag(R.id.adapter_item_data_key);
            } else {
                homeListItem = (HomeListItem) itemView.getTag(R.id.adapter_item_data_key);
            }
            Intent intent = null;
            if (homeListItem.getSubType() == 1) {
                intent = new Intent(getContext(), MainActivity.class);
                intent.putExtra(BaseActivity.EX_ID, homeListItem.getNewsItemList().get(position).getNewsId());
                intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(intent);
            } else if (homeListItem.getSubType() == 2) {
//                intent = new Intent(getContext(), NewesDetailActivity.class);
//                intent.putExtra(BaseActivity.EX_COLLECT_ITEM, CollectionUtils.convertData(homeListItem.getNewsItemList().get(position)));
//                startActivity(intent);
                SkipUtil.skipWithNewsItem(getContext(), homeListItem.getNewsItemList().get(position), Cache.getInstance().getCurrentChannelId());
            }
        }
    };

    private void sss() {
        dataAddHelper = new GreatestDataAddHelper();
        NewsItem item = NewsItem.createTestInstance(0, GreatestAdapter.VIEWTYPE_BANNER);
//        list.add(item);
        dataAddHelper.setBannerData(getContext(), item);
        item = NewsItem.createTestInstance(0, GreatestAdapter.VIEWTYPE_EXPRESS);
//        list.add(item1);
        dataAddHelper.setExpressData(getContext(), item);
        Titles ti = null;
//        ti = new Titles();
//        ti.setTitle(getString(R.string.hot_video));
//        ti.setViewType(GreatestAdapter.VIEWTYPE_TITLE_24);
//        list.add(ti);

        HomeLive hl = new HomeLive();
        hl.setViewType(GreatestAdapter.VIEWTYPE_LIVE);
        String[] vs = getResources().getStringArray(R.array.test_lives);
        String[] lss = getResources().getStringArray(R.array.test_long_strss);
        int vsl = vs.length, lssl = lss.length;
        ArrayList<LiveItem> ls = new ArrayList<>();
        int si = (int) (Math.random() * 3 + 1);
        for (int i = 0; i < si; i++) {
            LiveItem li = new LiveItem();
            li.setTitle(i + "-" + lss[(int) (Math.random() * lssl)]);
            int m = (int) (Math.random() * vsl * 10);
            if (m >= vsl) {
                m = m % vsl;
            }
            li.setLiveUrl(vs[m]);
            ls.add(li);
        }
        hl.setLiveList(ls);
        dataAddHelper.setLiveData(getContext(), hl);

        item = NewsItem.createTestInstance(0, GreatestAdapter.VIEWTYPE_POPULAR);
//        list.add(item2);
        dataAddHelper.setPopularData(getContext(), item);
        List<IListShowData> list = new ArrayList<>();
        ti = new Titles();
        JLog.e("30dp=" + DensityUtil.dip2px(30) + "   " + getResources().getDimensionPixelOffset(R.dimen.test));
        ti.setDateString("7月6日");
        ti.setViewType(GreatestAdapter.VIEWTYPE_TITLE_24);
        list.add(ti);
        for (int i = 0; i < 6; i++) {
            list.add(NewsItem.createTestInstance(i, GreatestAdapter.VIEWTYPE_NEWS_24));
        }
        ti = new Titles();
        ti.setDateString("7月5日");
        ti.setViewType(GreatestAdapter.VIEWTYPE_TITLE_24_CONTINUE);
        list.add(ti);
        for (int i = 0; i < 6; i++) {
            list.add(NewsItem.createTestInstance(i == 0 ? -2 : i, GreatestAdapter.VIEWTYPE_NEWS_24));
        }
        dataAddHelper.addOrSet24Datas(getContext(), list, true);
    }

}
